package com.alen.sun.dao;

import com.alen.sun.bean.Content;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface ContentMapper {
    /**
     * 获取所有
     * @return
     */
    @Select("select * from content order by contentId asc")
    List<Content> list();

    /**
     * 添加按键内容
     * @param content
     */
    @Insert("insert into content (contentId,details) values (#{contentId},#{details})")
    void add(Content content);

    /**
     * 根据ID删除内容
     * @param id
     */
    @Delete("delete from content where id=#{id}")
    void delete(Integer id);

    /**
     * 根据ID获取内容
     * @param id
     * @return
     */
    @Select("select * from content where id=#{id}")
    Content getById(Integer id);

    /**
     * 根据ID修改内容
     * @param content
     */
    @Update("update content set details = #{details} where contentId=#{contentId}")
    void update(Content content);

    /**
     * 根据ID列表批量删除
     * @param ids
     */
    @Delete({
            "<script>",
            "delete from content where contentId in",
            "<foreach item='id' collection='ids' open='(' separator=',' close=')'>#{id}</foreach>",
            "</script>"
    })
    void deletes(List<Integer> ids);
}
